import moment from 'moment'
import dayjs from 'dayjs'
// 计算指定时间是星期几
export function getweekday(date) {
    // date例如:'2022-03-05'
    var weekArray = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")
    var week = weekArray[new Date(date).getDay()]
    return week
}
export const colorConfig = {
    red: '#F6C0CC',
    green: '#91D1A0'
}

export const getDefultDate = () => {
    let tem = moment()
    if (["星期日", "星期六"].includes(getweekday(tem))) {
        tem = moment(tem).subtract(1, "day")
        console.log(9999, '星期六', tem)

    }
    if (["星期日", "星期六"].includes(getweekday(tem))) {
        tem = moment(tem).subtract(1, "day")
    }
    return tem
}

export const disabledDate = (current) => {
    // Can not select days before today and today

    if (["星期日", "星期六"].includes(getweekday(current))) {
        return true
    }
    return current && current > dayjs().endOf('day');
};

export const getLastDay = (preDay, formatStr = 'YYYY-MM-DD') => {
    if (["星期一"].includes(getweekday(preDay))) {
        return moment(preDay).subtract(3, 'day').format(formatStr)
    }
    return moment(preDay).subtract(1, 'day').format(formatStr)
}

export const getNextDay = (preDay, formatStr = 'YYYY-MM-DD') => {
    console.log("getweekday(preDay)", getweekday(preDay))
    if (["星期五"].includes(getweekday(preDay))) {
        let ret = moment(preDay).add(3, 'day').format(formatStr)
        if (moment(ret).isAfter(moment())) {
            return moment().format(formatStr)
        }
        return ret
    }
    let ret = moment(preDay).add(1, 'day').format(formatStr)
    if (moment(ret).isAfter(moment())) {
        return moment().format(formatStr)
    }
    return ret
}